/*
 * cudanCudaArrayDeviceMemory.h
 *
 *  Created on: Dec 11, 2009
 *      Author: daniel
 */

#ifndef CUDANCUDAARRAYMEMORY_H_
#define CUDANCUDAARRAYMEMORY_H_

#include "cudanDeviceMemory.h"

namespace CUDAN
{
	template<typename T, int D> class TextureMemory;

	// Defines a wrapper for a cudaArray.
	template<typename T, int D>
	class CudaArrayMemory : public DeviceMemory<T,D>
	{
	public:
		// cudaArray is an optimized array for texture reads.
		cudaArray* array;

		// Extent defines the dimension size in bytes.
		cudaExtent extent;

		// Channel format description describes the type and transfer direction.
		cudaChannelFormatDesc channelDesc;

	public:
		CudaArrayMemory();
		CudaArrayMemory(HostMemory<T,D>*);
		CudaArrayMemory(DeviceMemory<T,D>*);
		CudaArrayMemory(GlobalMemory<T,D>*);
		CudaArrayMemory(CudaArrayMemory<T,D>*);
		CudaArrayMemory(TextureMemory<T,D>*);
		CudaArrayMemory<T,D>* operator=(HostMemory<T,D>*);
		CudaArrayMemory<T,D>* operator=(DeviceMemory<T,D>*);
		CudaArrayMemory<T,D>* operator=(GlobalMemory<T,D>*);
		CudaArrayMemory<T,D>* operator=(CudaArrayMemory<T,D>*);
		CudaArrayMemory<T,D>* operator=(TextureMemory<T,D>*);
		virtual ~CudaArrayMemory();

	public:
		virtual void freeMemory();
		virtual void print();
		virtual void print(DimensionSizeVector&);
		virtual bool allocateMemory(DimensionSizeVector&);
		virtual bool copyFrom(HostMemory<T,D>*);
		virtual bool copyFrom(DeviceMemory<T,D>*);
		virtual bool copyFrom(GlobalMemory<T,D>*);
		virtual bool copyFrom(CudaArrayMemory<T,D>*);
		virtual bool copyFrom(TextureMemory<T,D>*);
		virtual bool copyTo(HostMemory<T,D>*);
		virtual bool copyTo(DeviceMemory<T,D>*);
		virtual bool copyTo(GlobalMemory<T,D>*);
		virtual bool copyTo(CudaArrayMemory<T,D>*);
		virtual bool copyTo(TextureMemory<T,D>*);
	};

	// Defines a wrapper for a 3D cudaArray.
	template<typename T>
	class CudaArrayMemory<T,3> : public DeviceMemory<T,3>
	{
	public:
		// cudaArray is an optimized array for texture reads.
		cudaArray* array;

		// Extent defines the dimension size in bytes.
		cudaExtent extent;

		// Channel format description describes the type and transfer direction.
		cudaChannelFormatDesc channelDesc;

	public:
		CudaArrayMemory();
		CudaArrayMemory(HostMemory<T,3>*);
		CudaArrayMemory(DeviceMemory<T,3>*);
		CudaArrayMemory(GlobalMemory<T,3>*);
		CudaArrayMemory(CudaArrayMemory<T,3>*);
		CudaArrayMemory(TextureMemory<T,3>*);
		CudaArrayMemory<T,3>* operator=(HostMemory<T,3>*);
		CudaArrayMemory<T,3>* operator=(DeviceMemory<T,3>*);
		CudaArrayMemory<T,3>* operator=(GlobalMemory<T,3>*);
		CudaArrayMemory<T,3>* operator=(CudaArrayMemory<T,3>*);
		CudaArrayMemory<T,3>* operator=(TextureMemory<T,3>*);
		virtual ~CudaArrayMemory();

	public:
		virtual void freeMemory();
		virtual void print();
		virtual void print(DimensionSizeVector&);
		virtual bool allocateMemory(DimensionSizeVector&);
		virtual bool copyFrom(HostMemory<T,3>*);
		virtual bool copyFrom(DeviceMemory<T,3>*);
		virtual bool copyFrom(GlobalMemory<T,3>*);
		virtual bool copyFrom(CudaArrayMemory<T,3>*);
		virtual bool copyFrom(TextureMemory<T,3>*);
		virtual bool copyTo(HostMemory<T,3>*);
		virtual bool copyTo(DeviceMemory<T,3>*);
		virtual bool copyTo(GlobalMemory<T,3>*);
		virtual bool copyTo(CudaArrayMemory<T,3>*);
		virtual bool copyTo(TextureMemory<T,3>*);
	};
}

#include "cudanCudaArrayMemory.cpp"

#endif /* CUDAFWCUDAARRAYDEVICEMEMORY_H_ */
